package WEB.JDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @ClassName JDBCDemo
 * @Description JDBC入门
 * @Author 2214361854
 * @Date 2022/3/9 14:31
 * @Version 1.0
 */
public class JDBCDemo {
    public static void main(String[] args) throws Exception {
        /**
         * com.mysql.jdbc.Driver 是 mysql-connector-java 5中的，
         * com.mysql.cj.jdbc.Driver 是 mysql-connector-java 6以及以上中的
         * MySQL5之后可省略注册驱动，自动加载META-INF/services/java.sql.Driver文件中的驱动类
         */

//        注册驱动
//        Class.forName("com.mysql.jdbc.Driver");

        //127.0.0.1
        String url = "jdbc:mysql://localhost:3306/abc?serverTimezone=UTC&?useUnicode=true&characterEncoding=utf8&useSSL=false";
        String username = "root";
        String password = "root";
        Connection coon = DriverManager.getConnection(url, username, password);

        //定义SQL
        String sql1 = "update student set sex='男' where id=1";

        //获取执行SQL对象
        Statement statement = coon.createStatement();

        //执行SQL
        int cont1 = statement.executeUpdate(sql1);
        //处理结果
        System.out.println(cont1);

        //释放资源
        statement.close();
        coon.close();
    }
}
